fs = require('fs'),
paths = require('path'),
util = require('util'),
pcontent = "";
number =0;
foldornumber=0;
// foldors;
foldors = new Array();
path = 'E:/test/myfile';
console.log('准备开始');
function tofoldor(callback,path){
    //path = 'E:/test/myfile';
     fs.readdir(path, function(err, files){
        if(err){console.log(err); return;}//若有错误则在控制台显示错误
        
        files.forEach( function (file) {
            fs.stat(path+'/'+file,function(err,statinfo){
                if(err){console.log(err); return;}
                if(!statinfo.isDirectory()){
                    //console.log("file:"+file); 
                    pcontent +="<li>"+fileone+"</li>\n";
                }
                else{
                    
                    console.log(path+'/'+file); 
                    callback(callback,path+'/'+file);
                }
            });            
        });

        var fileone;
        for(var n = 0 ; n<files.length ; n++){
            fileone = files[n];
            fs.stat(path+'/'+fileone,function(err,statinfo){
                if(err){console.log(err); return;}
                if(!statinfo.isDirectory()){
                    //console.log("file:"+fileone); 
                    pcontent +="<li>"+fileone+"</li>\n";
                }
                else{
                    //console.log(path+'/'+fileone); 
                    //callback(callback,path+'/'+fileone);
                    foldornumber++;
                    foldors[foldornumber-1]=path+'/'+fileone;
                }
            });
        }

        files.forEach( function (file) {
            fs.stat(path+'/'+file,function(err,statinfo){
                if(err){console.log(err); return;}
                if(!statinfo.isDirectory()){
                    console.log("file:"+file); 
                }
                else{
                    console.log(path+'/'+file); 
                    callback(callback,path+'/'+file);
                }
            });            
        });

     });
    if(foldornumber)
    callback(callback,path+'/'+fileone);
}
// function isfoldor(){

// }
function todoit(){
    pcontent +="<ul>myfile\n";
    tofoldor(tofoldor,path);
    pcontent +="</ul>";
}

param = 'jk';


function a(callback)
{
    for(b=0;b<=5;b++){
        console.log("我是parent函数a！————"+b); 
        if(b==2){
            console.log("调用回调函数"); 
            callback(); 
        }
    }
}
function b(){   
    console.log("我是回调函数b");   
  
}   
function test()   
{   
    a(b);   
} 
test()













function ergodic(onepath){
    //pcontent += "<ul>" + onepath + "<ul>" +'\n';
    console.log(++number);
    fs.readdir(onepath, function(err, files){
        //err 为错误 , files 文件名列表包含文件夹与文件
        if(err){
            console.log('error:\n' + err);
            return;
        }

        files.forEach( function(file){

            fs.stat(onepath + '/' + file, function(err, statinfo){
                if(err){console.log(err); return;}
                if(!statinfo.isDirectory()){
                // 读出所有的文件
                        //console.log('文件夹为:' + onepath);
                        //pcontent +="文件夹为:" + onepath;
                        //console.log('文件名为:'+file);
                        //pcontent +="文件名为:"+file;
                        //console.log('pcontent='+pcontent);
                        console.log('我在读取文件夹的路径'+onepath);
                }else{

                     // 如果是文件夹遍历
                    ergodic(onepath + '/' + file);
                }
            });

        });

    });
}
// ergodic(path)
